//
//  Request.m
//  GraduationProject;
//
//  Created by 伍宏伟 on 16/4/12.
//  Copyright © 2016年 伍宏伟. All rights reserved.
//

#import "Request.h"
#import "APIStoreSDK.h"

#define API_KEY "114d66be22bc4545b01f614bcd66ffff"

@interface Request ()



@end

@implementation Request


-(instancetype)requestWithCityName:(NSString *)cityName delegate:(id)delegate
{
    
    
    NSString *city = cityName;
    
    APISCallBack* callBack = [APISCallBack alloc];
    
    callBack.onSuccess = ^(long status, NSString* responseString) {
        NSLog(@"onSuccess");
        if(responseString != nil) {
            _responseResult = [@"success\n" stringByAppendingString: responseString];
            NSLog(@"%@",_responseResult);
        }
    };
    
    callBack.onError = ^(long status, NSString* responseString) {
        NSLog(@"onError");
        _responseResult= [@"error\n" stringByAppendingString: responseString];
    };
    
    callBack.onComplete = ^() {
        NSLog(@"onComplete");
    };

    NSString *url = @"http://apis.baidu.com/heweather/pro/weather";
    NSString *method = @"GET";
    NSMutableDictionary *parameter = [[NSMutableDictionary alloc] init];
    [parameter setObject:city forKey:@"city"];
    
    //请求API
    [ApiStoreSDK executeWithURL:url method:method apikey:@API_KEY parameter:parameter callBack:callBack];
    
    
    NSLog(@"55%@",self.responseResult);
    
    return self;
    
    
}



@end
